package com.example.madman.yuejian;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.madman.yuejian.Adapter.OneClubAdapter;
import com.example.madman.yuejian.Bean.ClubBean;
import com.example.madman.yuejian.Listener.RetrofitListener;
import com.example.madman.yuejian.Model.ClubModel;

public class ClubActivity extends AppCompatActivity implements RetrofitListener<ClubBean>{
    private TextView tel,address,info,time;
    private ImageView club_show,back;

    private OneClubAdapter oneClubAdapter;
    private RecyclerView recyclerView;
    private int clubid;
    private ClubBean data ;
    private Context context;
    private RecyclerView.LayoutManager layoutManager;
    private ClubModel clubModel;
    private RetrofitListener<ClubBean> listener2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club);

        clubid  = getIntent().getIntExtra("clubid",1);



        initui();
        conhttp();
       // http();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ClubActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
   /* private void http(){
        listener2 = new RetrofitListener<ClubBean>() {
            @Override
            public void onSuccess(ClubBean clubBean) {
                data = clubBean;
                if (clubid == clubBean.getClubid()){
                    tel.setText(data.getClubtel());
                }
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
            }
        };
    }*/


    private void initui(){
        tel = (TextView)findViewById(R.id.text_clubtel);
        address = (TextView)findViewById(R.id.text_clubaddress);
        info = (TextView)findViewById(R.id.text_clubinfo);
        time = (TextView)findViewById(R.id.text_clubtime);

        club_show = (ImageView)findViewById(R.id.image_dclub);
        back = (ImageView)findViewById(R.id.club_back);
    }

    private void conhttp(){
        clubModel = new ClubModel("gson");
        clubModel.getClubDetail(clubid,this);

    }

    @Override
    public void onSuccess(ClubBean clubBean) {
        data = clubBean;
        tel.setText("联系方式："+data.getClubtel());
        address.setText("地址："+data.getClubaddress());
        info.setText("介绍:"+data.getClubinfo());
        time.setText("营业时间："+data.getClubtime());

        Glide.with(this)
                .load("http://192.168.155.1/yuejian/public/static/assets/img/"+data.getClubpic())
                .placeholder(R.drawable.club)
                .into(club_show);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
    }
}
